package com.xdjd.mobile.business.constant;

import org.apache.commons.lang.StringUtils;

/**
 * 错误码业务类型枚举
 *
 * @author panjl
 */
public enum ErrorCodeEnum {

    default_error("-9", "服务器异常，请稍后再试"),
    send_sms_error("0001", "验证码发送失败，请重试"),
    challenge_count_finish("0002", "今日无挑战次数可用，请签到领取"),
    can_challenge_count_finish("0003", "今日已无挑战次数，请明天再来"),
    clock_repeat("0004", "今日已有挑战进行，点击跳转活动详情"),
    challenge_own("0005", "不可以挑战自己"),
    bonus_own("0006", "激励金额必须大于零"),
    bonus_add("0007", "追加金额必须大于零"),
    bonus_add_error("0008", "追加金额失败"),
    not_pay_type("0009", "暂不支持此支付方式"),
    balance_not_enough("0010", "余额不足");


    /**
     * 验证码业务类型代码
     */
    private String code;

    /**
     * 验证码业务类型描述
     */
    private String desc;

    private ErrorCodeEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static ErrorCodeEnum getByCode(String code) {
        if (code == null) {
            return null;
        }
        ErrorCodeEnum sts = null;
        for (ErrorCodeEnum stsEnum : ErrorCodeEnum.values()) {
            if (stsEnum.getCode().equals(code)) {
                sts = stsEnum;
                break;
            }
        }
        return sts;
    }

    public static ErrorCodeEnum getByDesc(String desc) {
        if (StringUtils.isEmpty(desc)) {
            return null;
        }
        ErrorCodeEnum sts = null;
        for (ErrorCodeEnum stsEnum : ErrorCodeEnum.values()) {
            if (stsEnum.getDesc().equals(desc)) {
                sts = stsEnum;
                break;
            }
        }
        return sts;
    }

    public String getDesc() {
        return desc;
    }

    public String getCode() {
        return code;
    }

}
